package org.wak.character
{
	import org.wak.character.display.AbstractCharacterDisplay;
	import org.wak.inventory.Inventory;
	import org.wak.inventory.InventoryItem;
	import org.wak.main.AdventureMaster;
	import org.wak.scene.Scene;
	
	/**
	 * Represents a character in the adventure. 
	 * 
	 */	
	public class AdventureCharacter
	{
		
		// The id of this character
		private var mCharacterId:String = "" ;
		
		// The character display for this character.
		private var mCharacterDisplay:AbstractCharacterDisplay = null ;
		
		// The character's name.
		private var mName:String = "" ;
		
		// TODO: Add inventory when inventory is ready.
		
		// The id of the scene where the character is.
		private var mCurrentSceneId:String = "" ;
		
		// CurrentScene of the character.
		private var mCurrentScene:Scene = null;
		
		// Character's inventory
		private var mInventory:Inventory = null ;
	
		//Character's description
		private var mDescription:String = "" ;
		
		// the character's speech color.
		private var mSpeechColor:uint = 0xFFFFFF ;
		
		private var mUpdatePerspective:Boolean = true ;
		
		/**
		 * Constructor 
		 * @param pCharDef the data to define an adventure character.
		 * 
		 */		
		public function AdventureCharacter(pCharDef:ICharacterDefinition)
		{
			mCharacterId = pCharDef.characterId ;
			mCharacterDisplay = AdventureMaster.CharactersMngr.GetCharacterDisplay(pCharDef.characterDisplayId) ;
			mCharacterDisplay.SetOwner(this);
			mName = pCharDef.interactionName ;
			
			mInventory = new Inventory();
			mDescription = pCharDef.description ;
			
			var fNewItem:InventoryItem = null ;
			for each( var itemId:String in pCharDef.inventory)
			{
				fNewItem = AdventureMaster.InventoryItemsMngr.GetInventoryItem( itemId ) ;
				mInventory.AddItem( fNewItem );
			}
			
			mSpeechColor = pCharDef.speechColor ;
			//trace(mCharacterId + " color:"+mSpeechColor )
			 
		}
		
		/**
		 * The id of the Scene where this character is.
		 * @param value a Scene id.
		 * 
		 */		
		public function set sceneId(value:String):void
		{
			if(value != "")
			{
				mCurrentSceneId = value ;
				mCurrentScene = AdventureMaster.SceneMngr.GetScene( value );
			}
		}
		
		/**
		 * Moves the character to the coordinates over the scene.
		 * Usually walking through. 
		 * @param pSceneX horizontal coordinate on the scene.
		 * @param pSceneY vertical coordinate on the scene
		 * 
		 */		
		public function MoveTo(pSceneX:Number, pSceneY:Number, pOnCompleteFunc:Function = null):void
		{
			mCurrentScene.MoveCharacterTo( this.mCharacterId, pSceneX, pSceneY,pOnCompleteFunc);
		}
		
		/**
		 * Makes the character speak. 
		 * @param pText Text to say
		 * @param pOnComplete function reference to call when the task is completed.
		 * 
		 */		
		public function Say(pText:String, pOnComplete:Function = null):void
		{
			AdventureMaster.DialogMngr.CharacterSay( mCharacterId, pText,pOnComplete);	
		}		

		/**
		 * 
		 * @private 
		 * 
		 */		
		public function get sceneId():String
		{
			return mCurrentSceneId ;
		}
		
		/**
		 * The character display representing this player. 
		 * @param value a new character display to represent the player.
		 * 
		 */		
		public function set characterDisplay(value:AbstractCharacterDisplay):void
		{
			mCharacterDisplay = value;
			mCharacterDisplay.SetOwner( this );
		}
		
		/**
		 * 
		 * @private 
		 * 
		 */		
		public function get characterDisplay():AbstractCharacterDisplay
		{
			return mCharacterDisplay ;
		}
		
		/**
		 * The character id.  
		 * @return String
		 * 
		 */		
		public function get characterId():String
		{
			return mCharacterId ;
		}
		
		
		/**
		 * The character's name.  
		 * @return String
		 * 
		 */		
		public function get interactionName():String
		{
			return mName ;
		}
		
		/**
		 * The character's inventory. 
		 * @return Inventory
		 * 
		 */		
		public function get inventory():Inventory
		{
			return mInventory
		}
		
		public function get description():String
		{
			return mDescription ;
		}
		
		/**
		 * The color of the text when this character speaks. 
		 * @return color of the spoken text by this character.
		 * 
		 */		
		public function get speechColor():uint 
		{
			return mSpeechColor ;
		}
		
		/**
		 * Enable or disable the perspective scaling in the scene. 
		 * @return 
		 * 
		 */		
		public function get perspectiveEnabled():Boolean
		{
			return mUpdatePerspective ;
		}
		

	}
}